using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using kxcxw.Data.Entities;

namespace kxcxw.Data.Mapping
{
	public class AnnouncementInfoMap : EntityTypeConfiguration<AnnouncementInfo>
	{
		public AnnouncementInfoMap()
		{
			// Primary Key
			this.HasKey(t => t.AnnouncementID);

			// Properties
			this.Property(t => t.AnnouncementID)
				.IsRequired()
				.HasMaxLength(36);
				
			this.Property(t => t.ItemID)
				.IsRequired()
				.HasMaxLength(36);
				
			this.Property(t => t.AnnouncementContent)
				.IsRequired()
				.HasMaxLength(500);
				
			this.Property(t => t.CreatePersonID)
				.IsRequired()
				.HasMaxLength(36);
				
			// Table & Column Mappings
			this.ToTable("AnnouncementInfo");
			this.Property(t => t.AnnouncementID).HasColumnName("AnnouncementID");
			this.Property(t => t.ItemID).HasColumnName("ItemID");
			this.Property(t => t.AnnouncementContent).HasColumnName("AnnouncementContent");
			this.Property(t => t.CreatePersonID).HasColumnName("CreatePersonID");
			this.Property(t => t.CreateDate).HasColumnName("CreateDate");

            // Relationships
            this.HasRequired(t => t.SysItemDetial)
                .WithMany(t => t.AnnouncementInfoes)
                .HasForeignKey(d => d.ItemID);

            this.HasRequired(t => t.SysUserInfo)
                .WithMany(t => t.AnnouncementInfoes)
                .HasForeignKey(d => d.CreatePersonID);
		}
	}
}

